﻿using System;
using System.Collections.Generic;

using System.Text;
using System.Security.Cryptography;
using System.IO;
using System.Web.Security;

 
   public class DEncrypt
	{
		private static string x83f3ea1d0a03c7e1 = "greatwang_tony";
		public static string Encrypt(string original)
		{
			return DEncrypt.Encrypt(original, DEncrypt.x83f3ea1d0a03c7e1);
		}
		public static string Decrypt(string original)
		{
			return DEncrypt.Decrypt(original, DEncrypt.x83f3ea1d0a03c7e1, Encoding.Default);
		}
		public static string Encrypt(string original, string key)
		{
			byte[] bytes = Encoding.Default.GetBytes(original);
			byte[] bytes2 = Encoding.Default.GetBytes(key);
			return Convert.ToBase64String(DEncrypt.Encrypt(bytes, bytes2));
		}
		public static string Decrypt(string original, string key)
		{
			return DEncrypt.Decrypt(original, key, Encoding.Default);
		}
		public static string Decrypt(string encrypted, string key, Encoding encoding)
		{
			byte[] encrypted2 = Convert.FromBase64String(encrypted);
			byte[] bytes = Encoding.Default.GetBytes(key);
			return encoding.GetString(DEncrypt.Decrypt(encrypted2, bytes));
		}
		public static byte[] Decrypt(byte[] encrypted)
		{
			byte[] bytes = Encoding.Default.GetBytes(DEncrypt.x83f3ea1d0a03c7e1);
			return DEncrypt.Decrypt(encrypted, bytes);
		}
		public static byte[] Encrypt(byte[] original)
		{
			byte[] bytes = Encoding.Default.GetBytes(DEncrypt.x83f3ea1d0a03c7e1);
			return DEncrypt.Encrypt(original, bytes);
		}
		public static byte[] MakeMD5(byte[] original)
		{
			MD5CryptoServiceProvider mD5CryptoServiceProvider = new MD5CryptoServiceProvider();
			return mD5CryptoServiceProvider.ComputeHash(original);
		}
		public static byte[] Encrypt(byte[] original, byte[] key)
		{
			return new TripleDESCryptoServiceProvider
			{
				Key = DEncrypt.MakeMD5(key),
				Mode = CipherMode.ECB
			}.CreateEncryptor().TransformFinalBlock(original, 0, original.Length);
		}
		public static byte[] Decrypt(byte[] encrypted, byte[] key)
		{
			return new TripleDESCryptoServiceProvider
			{
				Key = DEncrypt.MakeMD5(key),
				Mode = CipherMode.ECB
			}.CreateDecryptor().TransformFinalBlock(encrypted, 0, encrypted.Length);
		}
	}

   public class DESEncrypt
   {
       private static string x83f3ea1d0a03c7e1 = "greatwang_tony";
       public static string Encrypt(string Text)
       {
           return DESEncrypt.Encrypt(Text, DESEncrypt.x83f3ea1d0a03c7e1);
       }
       public static string Encrypt(string Text, string sKey)
       {
           return DESEncrypt.Encrypt(Text, sKey, CipherMode.CBC);
       }
       public static string Encrypt(string Text, string sKey, CipherMode mode)
       {
           return DESEncrypt.x6ac2c671d48f4e8d(Text, sKey, mode);
       }
       private static string x6ac2c671d48f4e8d(string xf9ad6fb78355fe13, string xac364f188af485ec, CipherMode xa4aa8b4150b11435)
       {
           DESCryptoServiceProvider dESCryptoServiceProvider = new DESCryptoServiceProvider();
           dESCryptoServiceProvider.Mode = xa4aa8b4150b11435;
           byte[] bytes = Encoding.Default.GetBytes(xf9ad6fb78355fe13);
           if (xa4aa8b4150b11435 != CipherMode.ECB)
           {
               dESCryptoServiceProvider.Key = Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile(xac364f188af485ec, "md5").Substring(0, 8));
               dESCryptoServiceProvider.IV = Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile(xac364f188af485ec, "md5").Substring(0, 8));
           }
           else
           {
               dESCryptoServiceProvider.Key = Encoding.ASCII.GetBytes(xac364f188af485ec);
               dESCryptoServiceProvider.IV = Encoding.ASCII.GetBytes(xac364f188af485ec);
           }
           MemoryStream memoryStream = new MemoryStream();
           CryptoStream cryptoStream = new CryptoStream(memoryStream, dESCryptoServiceProvider.CreateEncryptor(), CryptoStreamMode.Write);
           cryptoStream.Write(bytes, 0, bytes.Length);
           cryptoStream.FlushFinalBlock();
           StringBuilder stringBuilder = new StringBuilder();
           byte[] array = memoryStream.ToArray();
           for (int i = 0; i < array.Length; i++)
           {
               byte b = array[i];
               stringBuilder.AppendFormat("{0:X2}", b);
           }
           return stringBuilder.ToString();
       }
       public static string Decrypt(string Text)
       {
           return DESEncrypt.Decrypt(Text, DESEncrypt.x83f3ea1d0a03c7e1);
       }
       public static string Decrypt(string Text, string sKey)
       {
           return DESEncrypt.Decrypt(Text, sKey, CipherMode.CBC);
       }
       public static string Decrypt(string Text, string sKey, CipherMode mode)
       {
           return DESEncrypt.x554b149c1a3d99a3(Text, sKey, mode);
       }
       private static string x554b149c1a3d99a3(string xf9ad6fb78355fe13, string xac364f188af485ec, CipherMode xa4aa8b4150b11435)
       {
           DESCryptoServiceProvider dESCryptoServiceProvider = new DESCryptoServiceProvider();
           dESCryptoServiceProvider.Mode = xa4aa8b4150b11435;
           int num = xf9ad6fb78355fe13.Length / 2;
           byte[] array = new byte[num];
           for (int i = 0; i < num; i++)
           {
               int num2 = Convert.ToInt32(xf9ad6fb78355fe13.Substring(i * 2, 2), 16);
               array[i] = (byte)num2;
           }
           if (xa4aa8b4150b11435 != CipherMode.ECB)
           {
               dESCryptoServiceProvider.Key = Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile(xac364f188af485ec, "md5").Substring(0, 8));
               dESCryptoServiceProvider.IV = Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile(xac364f188af485ec, "md5").Substring(0, 8));
           }
           else
           {
               dESCryptoServiceProvider.Key = Encoding.ASCII.GetBytes(xac364f188af485ec);
               dESCryptoServiceProvider.IV = Encoding.ASCII.GetBytes(xac364f188af485ec);
           }
           MemoryStream memoryStream = new MemoryStream();
           CryptoStream cryptoStream = new CryptoStream(memoryStream, dESCryptoServiceProvider.CreateDecryptor(), CryptoStreamMode.Write);
           cryptoStream.Write(array, 0, array.Length);
           cryptoStream.FlushFinalBlock();
           return Encoding.Default.GetString(memoryStream.ToArray());
       }
   }
